import java.util.Vector;

/**
 * Class holding the structure of a Road.
 * @author Jared Lindbl�m, Prarthanaag
 */
public class Road {
	protected String name, type;
	protected double distance;
	protected int maxVehicles;
	protected Vector<Intersection> intersections;
	protected Metric metric;

	/**
	 * Constructor.
	 * @param name			The name of the road.
	 * @param weight		The weight of the road.
	 * @param maxVehicles	The maximum number of vehicles on this road.
	 * @param type			The road type (North/South, East/West).
	 */
	public Road(String name, double distance, int maxVehicles, Metric metric, String type) {
		this.name = name;
		this.distance = distance;
		this.maxVehicles = maxVehicles;
		this.type = type; // North/South or East/West
		intersections = new Vector<Intersection>();
		this.metric = metric;
	}

	/**
	 * Accessor Method (Name).
	 * @return	The name of the road.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Accessor Method (Type).
	 * @return	The road type (North/South, East/West).
	 */
	public String getType() {
		return type;
	}

	/**
	 * Accessor Method (Distance).
	 * @return The length of the road.
	 */
	public double getDistance() {
		return distance;
	}

	/**
	 * Dummy Method... Implemented in subclasses
	 * @param direction	The direction the vehicle is traveling.
	 * @return	The number of vehicles on the road.
	 */
	public int getNumVehicles (Direction direction) {
		/**
		 * Implemented in subclasses!
		 */
		return -1;
	}

	/**
	 * Accessor Method (Max Vehicles).
	 * @return	The maximum number of vehicles on this road.
	 */
	public int getMaxVehicles() {
		return maxVehicles;
	}

	/**
	 * Accessor Method (Intersection).
	 * @return The intersections associated with this road.
	 */
	public Intersection[] getIntersections() {
		Intersection[] i = new Intersection[intersections.size()];

		intersections.toArray(i);
		return i;
	}

	/**
	 * Updates the maximum number of vehicles on this road.
	 * @param maxVehicles	The new maximum number of vehicles on this road.
	 */
	public void updateMaxVehicles(int maxVehicles) {
		this.maxVehicles = maxVehicles;
	}

	/**
	 * Associates an intersection to this road.
	 * @param intersection	The intersection to associate to this road.
	 */
	public void addIntersection(Intersection intersection) {
		intersections.addElement(intersection);
	}
	
	public boolean generateSections() {
		/**
		 *  Implemented in subclasses!
		 */
		return false;
	}
	
	/**
	 * Accessor Method (Road Sections).
	 * @return The sections of this road.
	 */
	public Section[] getSections() {
		/**
		 * Implemented in subclasses!
		 */
		return null;
	}

	/**
	 * Prints out the structure of this road (for debugging).
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		String print = "Name: " + name + "\t\tMax Vehicles Per Section: " + maxVehicles + "\n";

		Intersection[] intersectionArray = new Intersection[intersections.size()];
		
		intersections.toArray(intersectionArray);

		print = print.concat("\n\t\t\t\tAssociated Intersections: (" + intersectionArray.length + " in total)\n\n");
		for (int i = 0; i < intersectionArray.length; i++) {
			print = print.concat("\t\t\t\t\tName: " + intersectionArray[i].getName() + "\n");
		}
		
		return print;
	}
}